home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / JOYSTICK.SWG / 0001_JOYSTCK1.PAS.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  3KB  |  120 lines

  1. Unit Joystick;
  2. Interface
  3.  Uses Crt;
  4.  
  5.  { Joystick Interface For Turbo Pascal V. 4.0 and above
  6.    Public Domain, November 1989 by
  7.    JonSoft Technologies Inc.
  8.    (C) 1989 JonSoft Technologies Inc. }
  9.  
  10. Const
  11.  centX : Byte=80;
  12.  centY : Byte=40;
  13.  Joyst : Boolean=True;
  14.  
  15. Procedure FastInitJS;
  16. Procedure BetterInitJS( range : Byte );
  17. Function joy_X : Byte;
  18. Function joy_Y : Byte;
  19. Function button_1 : Byte;
  20. Function button_2 : Byte;
  21. Function Horiz : shortint;
  22. Function Vert : shortint;
  23.  
  24.  
  25. Implementation
  26.  
  27. Const
  28.  rangexm : Byte=25;
  29.  rangeym : Byte=20;
  30.  rangexp : Byte=25;
  31.  rangeyp : Byte=25;
  32.  
  33. Function joy_X : Byte;
  34.   Var
  35.     x : Word;
  36.   begin
  37.     x := 0;
  38.     Port[$201] := $ff;
  39.     While Port[$201] and $1=1 do Inc(x);
  40.     joy_X := x;
  41.   end;
  42.  
  43. Function joy_Y : Byte;
  44.   Var
  45.     y : Word;
  46.   begin
  47.     y := 0;
  48.     Port[$201] := $0;
  49.     While Port[$201] and $2=2 do Inc(y);
  50.     joy_Y := y;
  51.   end;
  52.  
  53. Procedure FastInitJs;
  54.   begin
  55.     centX := joy_X;
  56.     centY := joy_Y;
  57.   end;
  58.  
  59. Function button_1 : Byte;
  60.   begin
  61.     button_1 := ((Port[$201] and $10) Xor $10) ShR 4;
  62.   end;
  63.  
  64. Function button_2 : Byte;
  65.   begin
  66.     button_2 := ((Port[$201] and $20) Xor $20) ShR 5;
  67.   end;
  68.  
  69. Procedure BetterInitJs(range : Byte);
  70.   Var
  71. (*    Ch : Char; *)
  72.     uprjoyX, uprjoyY, centrjoyX, centrjoyY, lowrjoyX, lowrjoyY : Byte;
  73.  
  74. begin
  75.  WriteLN('Are you using a joystick? (Button = yes, RETURN = no)');
  76.  Repeat
  77.   if button_1+button_2 > 0 then Joyst := True;
  78.   if KeyPressed then Joyst := False;
  79.  Until (button_1+button_2 > 0) or KeyPressed;
  80.  if Joyst = True then begin
  81.   Repeat Until button_1+button_2 = 0;
  82.   WriteLN('Move joystick to UPPER RIGHT corner and press a button.');
  83.   Repeat Until button_1+button_2 > 0;
  84.   uprjoyX := joy_X;
  85.   uprjoyY := joy_Y;
  86.   Repeat Until button_1+button_2 = 0;
  87.   WriteLN('Move joystick to CENTER and press a button.');
  88.   Repeat Until button_1+button_2 > 0;
  89.   centrjoyX := joy_X;
  90.   centrjoyY := joy_Y;
  91.   centX := centrjoyX;
  92.   centY := centrjoyY;
  93.   Repeat Until button_1+button_2 = 0;
  94.   WriteLN('Move joystick to LOWER LEFT CorNER and press a button.');
  95.   Repeat Until button_1+button_2 > 0;
  96.   lowrjoyX := joy_X;
  97.   lowrjoyY := joy_Y;
  98.   rangexm := (centrjoyX-uprjoyX) div range;
  99.   rangexp := (lowrjoyX-centrjoyX) div range;
  100.   rangeym := (centrjoyY-uprjoyY) div range;
  101.   rangeyp := (lowrjoyY-centrjoyY) div range;
  102.  end;
  103. end;
  104.  
  105. Function Horiz : shortint;
  106.   begin
  107.     if joy_X<centX-rangexm then Horiz := -1
  108.     else if joy_X > centX+rangexp then Horiz := 1
  109.     else Horiz := 0;
  110.   end;
  111.  
  112. Function Vert : shortint;
  113.   begin
  114.     if joy_Y<centY-rangeym then Vert := -1
  115.     else if joy_Y > centY+rangeyp then Vert := 1
  116.     else Vert := 0;
  117.   end;
  118.  
  119. end.
  120.